<?php
namespace app\index\controller;
use think\Controller;
use app\model\NoteCateModel;
use app\model\NoteModel;

class Forum extends Controller
{

    //论坛首页
    public function index()
    {
        $note = new NoteModel();
        $where_note = ['state'=>1];
        $note_list = $note->getNoteList($where_note);

        $cate = new NoteCateModel();
        $where_cate = ['state'=>1];
        $cate_list = $cate->getAllCates($where_cate);

        $this->assign('note_list',$note_list);
        $this->assign('cate_list',$cate_list);
        return $this->fetch();
    }

    //案列
    public function case()
    {
        return $this->fetch();
    }

    //帖子页
    public function note()
    {

        $cate = new NoteModel();
        $where = ['state'=>1];
        $note_list = $cate->getNoteList($where);
        $this->assign('note_list',$note_list);
        return $this->fetch();
    }

    //新增帖子
    public function addnote()
    {
        if (request()->isPost()) {
            $param = input("post.");
            $note = new NoteModel();

            $flag = $note->insertNote($param);

//            $this->success('新增成功', $flag['data']);
//            $this->redirect($flag['data']);
            return json(msg($flag['code'], $flag['data'], $flag['msg']));
        }else{
            $cate = new NoteCateModel();
            $where = ['state'=>1];
            $cate_list = $cate->getAllCates($where);
            $this->assign('cate_list',$cate_list);
            return $this->fetch();
        }

    }

    //帖子详情
    public function notedetail()
    {
        return $this->fetch();
    }

}
